home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / wifisetupdialog.pyc (.txt) < prev   
Python Compiled Bytecode  |  2009-10-28  |  26KB  |  735 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import operator
  5. from base.g import *
  6. from base import device, utils, models, wifi
  7. from base.codes import *
  8. from ui_utils import *
  9. from PyQt4.QtCore import *
  10. from PyQt4.QtGui import *
  11. from wifisetupdialog_base import Ui_Dialog
  12. PAGE_INTRO = 0
  13. PAGE_DEVICES = 1
  14. PAGE_NETWORK = 2
  15. PAGE_CONFIGURE_WIFI = 3
  16. PAGE_EXIT = 4
  17. BUTTON_NEXT = 0
  18. BUTTON_FINISH = 1
  19. BUTTON_CONNECT = 3
  20. SUCCESS_NOT_CONNECTED = 0
  21. SUCCESS_AUTO_IP = 1
  22. SUCCESS_CONNECTED = 2
  23. ASSOCIATE_DELAY = 30
  24. REFRESH_INTERVAL = 20
  25.  
  26. class DeviceTableWidgetItem(QTableWidgetItem):
  27.     
  28.     def __init__(self, text, device_uri):
  29.         QTableWidgetItem.__init__(self, text, QTableWidgetItem.UserType)
  30.         self.device_uri = device_uri
  31.  
  32.  
  33.  
  34. class WifiSetupDialog(QDialog, Ui_Dialog):
  35.     
  36.     def __init__(self, parent, device_uri = None, standalone = True):
  37.         QDialog.__init__(self, parent)
  38.         self.setupUi(self)
  39.         self.device_uri = device_uri
  40.         self.devices = { }
  41.         self.networks = { }
  42.         self.ssid = ''
  43.         self.directed = False
  44.         self.show_extended = False
  45.         self.bus = 'usb'
  46.         self.search = ''
  47.         self.max_page = PAGE_EXIT
  48.         self.location_cache = { }
  49.         self.dev = None
  50.         self.success = SUCCESS_NOT_CONNECTED
  51.         self.ip = '0.0.0.0'
  52.         self.hn = ''
  53.         self.standalone = standalone
  54.         self.initUi()
  55.         if self.device_uri is None:
  56.             QTimer.singleShot(0, self.showIntroPage)
  57.         else:
  58.             QTimer.singleShot(0, self.showNetworkPage)
  59.  
  60.     
  61.     def initUi(self):
  62.         self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
  63.         self.connect(self.CancelButton, SIGNAL('clicked()'), self.CancelButton_clicked)
  64.         self.connect(self.BackButton, SIGNAL('clicked()'), self.BackButton_clicked)
  65.         self.connect(self.NextButton, SIGNAL('clicked()'), self.NextButton_clicked)
  66.         self.initIntroPage()
  67.         self.initDevicesPage()
  68.         self.initNetworkPage()
  69.         self.initConfigWifiPage()
  70.         self.initExitPage()
  71.  
  72.     
  73.     def initIntroPage(self):
  74.         self.Picture.setPixmap(load_pixmap('usb_connection', 'other'))
  75.         self.InfoIcon.setPixmap(load_pixmap('info', '16x16'))
  76.         if self.standalone:
  77.             self.MainTitleLabel.setText(self._WifiSetupDialog__tr('This utility allows you configure your wireless capable printer using a temporary USB connection. You will be prompted to disconnect the USB cable once wireless network setup is complete.\n\n<p><i>Note: This configuration utility does not setup (install) your printer on this computer. Use hp-setup to setup your printer after it has been configured on the network by this utility.</i></p>\n<p><i>Note: Only select wireless capable printers are supported by this utility.</i></p>'))
  78.         else:
  79.             self.MainTitleLabel.setText(self._WifiSetupDialog__tr('This utility allows you configure your wireless capable printer using a temporary USB connection. You will be prompted to disconnect the USB cable once wireless network setup is complete.\n\n<p><i>Note: Printer setup (installation) will continue after your printer is configured on the network.</i></p>\n<p><i>Note: Only select wireless capable printers are supported by this utility.</i></p>'))
  80.  
  81.     
  82.     def showIntroPage(self):
  83.         self.BackButton.setEnabled(False)
  84.         self.NextButton.setEnabled(True)
  85.         self.displayPage(PAGE_INTRO)
  86.  
  87.     
  88.     def initDevicesPage(self):
  89.         self.connect(self.RefreshButton, SIGNAL('clicked()'), self.RefreshButton_clicked)
  90.  
  91.     
  92.     def showDevicesPage(self):
  93.         self.BackButton.setEnabled(True)
  94.         self.setNextButton(BUTTON_NEXT)
  95.         beginWaitCursor()
  96.         
  97.         try:
  98.             if not self.devices:
  99.                 log.info('Searching on USB bus...')
  100.                 filter_dict = {
  101.                     'wifi-config': (operator.gt, WIFI_CONFIG_NONE) }
  102.                 self.devices = device.probeDevices([
  103.                     self.bus], 0, 0, filter_dict, self.search)
  104.         finally:
  105.             endWaitCursor()
  106.  
  107.         self.clearDevicesTable()
  108.         if self.devices:
  109.             self.NextButton.setEnabled(True)
  110.             self.DevicesFoundIcon.setPixmap(load_pixmap('info', '16x16'))
  111.             if len(self.devices) == 1:
  112.                 self.DevicesFoundLabel.setText(self._WifiSetupDialog__tr('<b>1 wireless capable device found.</b> Click <i>Next</i> to continue.'))
  113.             else:
  114.                 self.DevicesFoundLabel.setText(self._WifiSetupDialog__tr('<b>%1 wireless capable devices found.</b> Select the device to install and click <i>Next</i> to continue.').arg(len(self.devices)))
  115.             self.loadDevicesTable()
  116.         else:
  117.             self.NextButton.setEnabled(False)
  118.             self.DevicesFoundIcon.setPixmap(load_pixmap('error', '16x16'))
  119.             log.error('No devices found on bus: %s' % self.bus)
  120.             self.DevicesFoundLabel.setText(self._WifiSetupDialog__tr('<b>No wireless capable devices found.</b><br>Plug in your printer with a USB cable and click <i>Refresh</i> to search again.'))
  121.         self.displayPage(PAGE_DEVICES)
  122.  
  123.     
  124.     def loadDevicesTable(self):
  125.         self.DevicesTableWidget.setSortingEnabled(False)
  126.         self.DevicesTableWidget.setRowCount(len(self.devices))
  127.         headers = [
  128.             self._WifiSetupDialog__tr('Model'),
  129.             self._WifiSetupDialog__tr('Device URI')]
  130.         device_uri_col = 1
  131.         self.DevicesTableWidget.setColumnCount(len(headers))
  132.         self.DevicesTableWidget.setHorizontalHeaderLabels(headers)
  133.         flags = Qt.ItemIsSelectable | Qt.ItemIsEnabled
  134.         for row, d in enumerate(self.devices):
  135.             (back_end, is_hp, bus, model, serial, dev_file, host, zc, port) = device.parseDeviceURI(d)
  136.             model_ui = models.normalizeModelUIName(model)
  137.             i = DeviceTableWidgetItem(QString(model_ui), d)
  138.             i.setFlags(flags)
  139.             self.DevicesTableWidget.setItem(row, 0, i)
  140.             i = QTableWidgetItem(QString(d))
  141.             i.setFlags(flags)
  142.             self.DevicesTableWidget.setItem(row, device_uri_col, i)
  143.         
  144.         self.DevicesTableWidget.resizeColumnsToContents()
  145.         self.DevicesTableWidget.setSortingEnabled(True)
  146.         self.DevicesTableWidget.sortItems(0)
  147.         self.DevicesTableWidget.selectRow(0)
  148.  
  149.     
  150.     def clearDevicesTable(self):
  151.         self.DevicesTableWidget.clear()
  152.         self.DevicesTableWidget.setRowCount(0)
  153.         self.DevicesTableWidget.setColumnCount(0)
  154.  
  155.     
  156.     def RefreshButton_clicked(self):
  157.         self.clearDevicesTable()
  158.         self.devices = []
  159.         QTimer.singleShot(0, self.showDevicesPage)
  160.  
  161.     
  162.     def initNetworkPage(self):
  163.         self.NetworksTableWidget.setIconSize(QSize(34, 20))
  164.         self.ShowExtendedCheckBox.setChecked(False)
  165.         self.connect(self.ShowExtendedCheckBox, SIGNAL('clicked(bool)'), self.ShowExtendedCheckBox_clicked)
  166.         self.connect(self.SearchPushButton, SIGNAL('clicked()'), self.SearchPushButton_clicked)
  167.         self.connect(self.UndirectedRadioButton, SIGNAL('clicked(bool)'), self.UndirectedRadioButton_clicked)
  168.         self.connect(self.DirectedRadioButton, SIGNAL('clicked(bool)'), self.DirectedRadioButton_clicked)
  169.         self.connect(self.NetworksTableWidget, SIGNAL('itemSelectionChanged()'), self.NetworksTableWidget_itemSelectionChanged)
  170.  
  171.     
  172.     def showNetworkPage(self):
  173.         if self.dev is None:
  174.             
  175.             try:
  176.                 self.dev = device.Device(self.device_uri)
  177.             except Error:
  178.                 e = None
  179.                 FailureUI(self, self._WifiSetupDialog__tr('<b>Error opening device:</b><p>%1</p><p>(%2)</p>').arg(self.device_uri).arg(QString(e[0])))
  180.                 if self.dev is not None:
  181.                     self.dev.close()
  182.                 
  183.                 self.close()
  184.                 return None
  185.             
  186.  
  187.         None<EXCEPTION MATCH>Error
  188.         self.networks.clear()
  189.         self.num_networks = 0
  190.         
  191.         try:
  192.             (self.adaptor_id, name, state, presence) = wifi.getWifiAdaptorID(self.dev)
  193.         except Error:
  194.             e = None
  195.             self.showIOError(e)
  196.             return None
  197.  
  198.         log.debug('Adaptor ID: %s' % self.adaptor_id)
  199.         log.debug('Adaptor name: %s' % name)
  200.         log.debug('Adaptor state: %s' % state)
  201.         log.debug('Adaptor presence: %s' % presence)
  202.         if self.adaptor_id == -1:
  203.             FailureUI(self, self._WifiSetupDialog__tr('<b>Unable to locate wireless hardware on device.</b>'))
  204.             if self.dev is not None:
  205.                 self.dev.close()
  206.             
  207.             self.close()
  208.         
  209.         log.debug('Turning on wireless radio...')
  210.         
  211.         try:
  212.             wifi.setAdaptorPower(self.dev, self.adaptor_id)
  213.         except Error:
  214.             e = None
  215.             self.showIOError(e)
  216.             return None
  217.  
  218.         self.performScan()
  219.         self.setNextButton(BUTTON_NEXT)
  220.         self.displayPage(PAGE_NETWORK)
  221.  
  222.     
  223.     def performScan(self):
  224.         beginWaitCursor()
  225.         error = False
  226.         
  227.         try:
  228.             self.ssid = unicode(self.SSIDLineEdit.text())
  229.             if self.directed and self.ssid:
  230.                 
  231.                 try:
  232.                     self.networks = wifi.performScan(self.dev, self.ssid)
  233.                 except Error:
  234.                     e = None
  235.                     self.showIOError(e)
  236.                     return None
  237.                 
  238.  
  239.             None<EXCEPTION MATCH>Error
  240.             
  241.             try:
  242.                 self.networks = wifi.performScan(self.dev)
  243.             except Error:
  244.                 e = None
  245.                 self.showIOError(e)
  246.                 return None
  247.  
  248.         finally:
  249.             self.dev.close()
  250.             endWaitCursor()
  251.  
  252.         self.num_networks = self.networks['numberofscanentries']
  253.         self.clearNetworksTable()
  254.         if self.num_networks:
  255.             self.NextButton.setEnabled(True)
  256.             self.NetworksFoundIcon.setPixmap(load_pixmap('info', '16x16'))
  257.             if self.num_networks == 1:
  258.                 self.NetworksFoundLabel.setText(self._WifiSetupDialog__tr('<b>1 wireless network found. </b> If the wireless network you would like to connect to is not listed, try entering a wireless network name and/or press <i>Search</i> to search again.'))
  259.             else:
  260.                 self.NetworksFoundLabel.setText(self._WifiSetupDialog__tr('<b>%1 wireless networks found.</b> If the wireless network you would like to connect to is not listed, try entering a wireless network name and/or press <i>Search</i> to search again.').arg(self.num_networks))
  261.             self.loadNetworksTable()
  262.         else:
  263.             self.NextButton.setEnabled(False)
  264.             self.NetworksFoundIcon.setPixmap(load_pixmap('error', '16x16'))
  265.             log.warning('No wireless networks found.')
  266.             self.NetworksFoundLabel.setText(self._WifiSetupDialog__tr('<b>No wireless networks found.</b><br>Enter a wireless network name and/or press <i>Search</i> to search again.'))
  267.  
  268.     
  269.     def ShowExtendedCheckBox_clicked(self, b):
  270.         self.show_extended = b
  271.         self.loadNetworksTable()
  272.  
  273.     
  274.     def SearchPushButton_clicked(self):
  275.         self.performScan()
  276.         self.loadNetworksTable()
  277.  
  278.     
  279.     def UndirectedRadioButton_clicked(self, b):
  280.         self.directed = not b
  281.         self.SSIDLineEdit.setEnabled(not b)
  282.  
  283.     
  284.     def DirectedRadioButton_clicked(self, b):
  285.         self.directed = b
  286.         self.SSIDLineEdit.setEnabled(b)
  287.  
  288.     
  289.     def loadNetworksTable(self):
  290.         (self.n, self.network) = (0, u'')
  291.         if self.num_networks:
  292.             beginWaitCursor()
  293.             
  294.             try:
  295.                 if self.show_extended:
  296.                     for n in xrange(self.num_networks):
  297.                         bssid = self.networks['bssid-%d' % n]
  298.                         ss = self.networks['signalstrength-%d' % n]
  299.                         
  300.                         try:
  301.                             self.location_cache[bssid]
  302.                         except KeyError:
  303.                             location = wifi.getLocation(bssid, ss)
  304.                             lat = self.networks['latitude-%d' % n] = location.get('latitude', 'Unknown')
  305.                             lng = self.networks['longitude-%d' % n] = location.get('longitude', 'Unknown')
  306.                             address = self.networks['address-%d' % n] = location.get('address', 'Unknown')
  307.                             self.location_cache[bssid] = (lat, lng, address)
  308.                             continue
  309.  
  310.                         (self.networks['latitude-%d' % n], self.networks['longitude-%d' % n], self.networks['address-%d' % n]) = self.location_cache[bssid]
  311.                     
  312.                 
  313.                 self.NetworksTableWidget.setSortingEnabled(False)
  314.                 self.NetworksTableWidget.setRowCount(self.num_networks)
  315.                 headers = [
  316.                     self._WifiSetupDialog__tr('Network Name (SSID)'),
  317.                     self._WifiSetupDialog__tr('Signal Strength'),
  318.                     self._WifiSetupDialog__tr('Security'),
  319.                     self._WifiSetupDialog__tr('Mode')]
  320.                 if self.show_extended:
  321.                     headers.extend([
  322.                         self._WifiSetupDialog__tr('Channel'),
  323.                         self._WifiSetupDialog__tr('Address (BSSID)'),
  324.                         self._WifiSetupDialog__tr('Location'),
  325.                         self._WifiSetupDialog__tr('Lat/Long')])
  326.                 
  327.                 self.NetworksTableWidget.setColumnCount(len(headers))
  328.                 self.NetworksTableWidget.setHorizontalHeaderLabels(headers)
  329.                 enabled_flags = Qt.ItemIsSelectable | Qt.ItemIsEnabled
  330.                 for n in xrange(self.num_networks):
  331.                     name = self.networks['ssid-%d' % n]
  332.                     if name == '(unknown)':
  333.                         flags = None
  334.                     else:
  335.                         flags = enabled_flags
  336.                     ss = self.networks['signalstrength-%d' % n]
  337.                     sec = self.networks['encryptiontype-%d' % n]
  338.                     mode = self.networks['communicationmode-%d' % n]
  339.                     log.debug('%d: Name=%s, strength=%s, security=%s, mode=%s' % (n, name, ss, sec, mode))
  340.                     if self.show_extended:
  341.                         chn = self.networks['channel-%d' % n]
  342.                         dbm = self.networks['dbm-%d' % n]
  343.                         bssid = self.networks['bssid-%d' % n]
  344.                         address = self.networks['address-%d' % n]
  345.                         lat = self.networks['latitude-%d' % n]
  346.                         lng = self.networks['longitude-%d' % n]
  347.                         log.debug('%d: channel=%d bssid=%s dbm=%s lat=%s long=%s address=%s' % (n, chn, bssid, dbm, lat, lng, address))
  348.                     
  349.                     i = QTableWidgetItem(QString(name))
  350.                     if flags is not None:
  351.                         i.setFlags(flags)
  352.                     
  353.                     i.setData(Qt.UserRole, QVariant(n))
  354.                     self.NetworksTableWidget.setItem(n, 0, i)
  355.                     pixmap = load_pixmap('signal%d' % ss, 'other')
  356.                     if self.show_extended:
  357.                         i = QTableWidgetItem(QIcon(pixmap), self._WifiSetupDialog__tr('%1/5 (%2 dBm)').arg(ss).arg(dbm))
  358.                     else:
  359.                         i = QTableWidgetItem(QIcon(pixmap), self._WifiSetupDialog__tr('%1/5').arg(ss))
  360.                     if flags is not None:
  361.                         i.setFlags(flags)
  362.                     
  363.                     self.NetworksTableWidget.setItem(n, 1, i)
  364.                     i = QTableWidgetItem(QString(sec))
  365.                     if flags is not None:
  366.                         i.setFlags(flags)
  367.                     
  368.                     self.NetworksTableWidget.setItem(n, 2, i)
  369.                     i = QTableWidgetItem(QString(mode))
  370.                     if flags is not None:
  371.                         i.setFlags(flags)
  372.                     
  373.                     self.NetworksTableWidget.setItem(n, 3, i)
  374.                     if self.show_extended:
  375.                         i = QTableWidgetItem(QString(str(chn)))
  376.                         if flags is not None:
  377.                             i.setFlags(flags)
  378.                         
  379.                         self.NetworksTableWidget.setItem(n, 4, i)
  380.                         i = QTableWidgetItem(QString(bssid))
  381.                         if flags is not None:
  382.                             i.setFlags(flags)
  383.                         
  384.                         self.NetworksTableWidget.setItem(n, 5, i)
  385.                         i = QTableWidgetItem(QString(address))
  386.                         if flags is not None:
  387.                             i.setFlags(flags)
  388.                         
  389.                         self.NetworksTableWidget.setItem(n, 6, i)
  390.                         i = QTableWidgetItem(QString('%1/%2').arg(lat).arg(lng))
  391.                         if flags is not None:
  392.                             i.setFlags(flags)
  393.                         
  394.                         self.NetworksTableWidget.setItem(n, 7, i)
  395.                         continue
  396.                 
  397.                 self.NetworksTableWidget.resizeColumnsToContents()
  398.                 self.NetworksTableWidget.setSortingEnabled(True)
  399.                 self.NetworksTableWidget.sortItems(1, Qt.DescendingOrder)
  400.                 self.NetworksTableWidget.selectRow(0)
  401.                 self.NetworksTableWidget.emit(SIGNAL('itemSelectionChanged()'))
  402.             finally:
  403.                 endWaitCursor()
  404.                 self.NextButton.setEnabled(True)
  405.  
  406.         else:
  407.             self.NextButton.setEnabled(False)
  408.  
  409.     
  410.     def NetworksTableWidget_itemSelectionChanged(self):
  411.         row = self.NetworksTableWidget.currentRow()
  412.         item = self.NetworksTableWidget.item(row, 0)
  413.         (n, ok) = item.data(Qt.UserRole).toInt()
  414.         if ok:
  415.             sec = self.networks['encryptiontype-%d' % n]
  416.             if sec.lower() == 'none':
  417.                 self.setNextButton(BUTTON_CONNECT)
  418.             else:
  419.                 self.setNextButton(BUTTON_NEXT)
  420.         
  421.  
  422.     
  423.     def clearNetworksTable(self):
  424.         self.DevicesTableWidget.clear()
  425.         self.DevicesTableWidget.setRowCount(0)
  426.         self.DevicesTableWidget.setColumnCount(0)
  427.  
  428.     
  429.     def RefreshButton2_clicked(self):
  430.         self.clearNetworksTable()
  431.         self.networks = { }
  432.         QTimer.singleShot(0, self.showNetworkPage)
  433.  
  434.     
  435.     def initConfigWifiPage(self):
  436.         self.connect(self.ShowKeyCheckBox, SIGNAL('toggled(bool)'), self.ShowKeyCheckBox_toggled)
  437.  
  438.     
  439.     def showConfigWifiPage(self):
  440.         self.setNextButton(BUTTON_CONNECT)
  441.         self.SSIDLabel.setText(self.network)
  442.         font = QFont()
  443.         font.setPointSize(12)
  444.         self.SSIDLabel.setFont(font)
  445.         self.KeyLineEdit.setText(QString())
  446.         self.ShowKeyCheckBox.setChecked(False)
  447.         self.StrengthIcon.setPixmap(load_pixmap('signal%d' % self.ss, 'other'))
  448.         self.ConfigureIcon.setPixmap(load_pixmap('info', '16x16'))
  449.         self.KeysIcon.setPixmap(load_pixmap('keys', '32x32'))
  450.         if 'wpa' in self.security.lower():
  451.             self.WPARadioButton.setChecked(True)
  452.         elif 'wep' in self.security.lower():
  453.             self.WEPRadioButton.setChecked(True)
  454.         
  455.         self.KeyLineEdit.setFocus()
  456.         self.KeyLineEdit.setEchoMode(QLineEdit.Password)
  457.         self.displayPage(PAGE_CONFIGURE_WIFI)
  458.  
  459.     
  460.     def ShowKeyCheckBox_toggled(self, b):
  461.         if b:
  462.             self.KeyLineEdit.setEchoMode(QLineEdit.Normal)
  463.         else:
  464.             self.KeyLineEdit.setEchoMode(QLineEdit.Password)
  465.  
  466.     
  467.     def initExitPage(self):
  468.         self.connect(self.PageSpinBox, SIGNAL('valueChanged(int)'), self.PageSpinBox_valueChanged)
  469.         self.RefreshTimer = QTimer(self)
  470.         self.connect(self.RefreshTimer, SIGNAL('timeout()'), self.RefreshTimer_timeout)
  471.         self.pages = []
  472.         self.page_index = 0
  473.         self.PageSpinBox.setMinimum(1)
  474.  
  475.     
  476.     def showExitPage(self):
  477.         self.setNextButton(BUTTON_FINISH)
  478.         self.NextButton.setEnabled(False)
  479.         self.CancelButton.setEnabled(True)
  480.         self.SSIDLabel_2.setText(QString(self.network))
  481.         self.ip = '0.0.0.0'
  482.         self.hn = ''
  483.         self.success = SUCCESS_NOT_CONNECTED
  484.         beginWaitCursor()
  485.         
  486.         try:
  487.             (self.ip, _, addressmode, subnetmask, gateway, pridns, sec_dns) = wifi.getIPConfiguration(self.dev, self.adaptor_id)
  488.             vsa_codes = wifi.getVSACodes(self.dev)
  489.             (ss_max, ss_min, ss_val, ss_dbm) = wifi.getSignalStrength(self.dev, self.adaptor_id)
  490.             self.hn = wifi.getHostname(self.dev)
  491.         except Error:
  492.             e = None
  493.             self.showIOError(e)
  494.             return None
  495.         finally:
  496.             self.dev.close()
  497.             endWaitCursor()
  498.  
  499.         if addressmode.lower() == 'dhcp':
  500.             self.success = SUCCESS_CONNECTED
  501.         elif addressmode.lower() == 'autoip':
  502.             self.success = SUCCESS_AUTO_IP
  503.         
  504.         if self.ip == '0.0.0.0':
  505.             self.success = SUCCESS_NOT_CONNECTED
  506.         
  507.         self.pages = []
  508.         if self.success == SUCCESS_NOT_CONNECTED:
  509.             self.pages.append((self._WifiSetupDialog__tr('<b>Your printer has not been connected to the wireless network.</b> A valid connection to a wireless network can take up to 2 minutes. This screen will automatically refresh every %1 seconds.<p>If your printer fails to connect within a reasonable time, there may be a problem with your configuration.').arg(REFRESH_INTERVAL), load_pixmap('error', '16x16')))
  510.             self.RefreshTimer.start(REFRESH_INTERVAL * 1000)
  511.         elif self.success == SUCCESS_AUTO_IP:
  512.             self.pages.append((self._WifiSetupDialog__tr('Your printer has been connected to the wireless network, but it has been assigned an address which may not be usable.'), load_pixmap('warning', '16x16')))
  513.             self.RefreshTimer.start(REFRESH_INTERVAL * 1000)
  514.         elif self.standalone:
  515.             self.pages.append((self._WifiSetupDialog__tr('Your printer has been successfully configured on the wireless network. You may now unplug the USB cable. To setup the printer, now run <pre>hp-setup.</pre>'), load_pixmap('info', '16x16')))
  516.         else:
  517.             self.pages.append((self._WifiSetupDialog__tr('Your printer has been successfully configured on the wireless network. You may now unplug the USB cable.'), load_pixmap('info', '16x16')))
  518.         self.CancelButton.setEnabled(False)
  519.         self.BackButton.setEnabled(False)
  520.         self.RefreshTimer.stop()
  521.         if addressmode is None:
  522.             self.AddressModeLabel.setText(self._WifiSetupDialog__tr('Unknown'))
  523.         else:
  524.             self.AddressModeLabel.setText(QString(addressmode))
  525.         if self.hn is None:
  526.             self.HostnameLabel.setText(self._WifiSetupDialog__tr('Unknown'))
  527.         else:
  528.             self.HostnameLabel.setText(QString(self.hn))
  529.         self.IPAddressLabel.setText(QString(self.ip))
  530.         self.GatewayLabel.setText(QString(gateway))
  531.         self.DNSLabel.setText(QString(pridns))
  532.         self.NextButton.setEnabled(True)
  533.         self.SignalStrengthLabel.setText(QString('%1/%2 (%3 dBm)').arg(ss_val).arg(ss_max).arg(ss_dbm))
  534.         self.SignalStrengthIcon.setPixmap(load_pixmap('signal%d' % ss_val, 'other'))
  535.         for c, s in vsa_codes:
  536.             ss = s.lower()
  537.             if ss.startswith('info'):
  538.                 pixmap = load_pixmap('info', '16x16')
  539.             elif ss.startswith('warn'):
  540.                 pixmap = load_pixmap('warning', '16x16')
  541.             elif ss.startswith('crit'):
  542.                 pixmap = load_pixmap('error', '16x16')
  543.             else:
  544.                 pixmap = load_pixmap('info', '16x16')
  545.             self.pages.append((device.queryString('vsa_%s' % str(c).zfill(3)), pixmap))
  546.         
  547.         num_pages = len(self.pages)
  548.         self.PageSpinBox.setMaximum(num_pages)
  549.         self.PageSpinBox.setEnabled(num_pages > 1)
  550.         self.PageSpinBox.setValue(1)
  551.         self.PageLabel.setEnabled(num_pages > 1)
  552.         self.PageLabel2.setEnabled(num_pages > 1)
  553.         self.PageLabel.setText(self._WifiSetupDialog__tr('of %1').arg(num_pages))
  554.         self.page_index = 0
  555.         self.ExitLabel.setText(self.pages[self.page_index][0])
  556.         self.ExitIcon.setPixmap(self.pages[self.page_index][1])
  557.         self.displayPage(PAGE_EXIT)
  558.  
  559.     
  560.     def PageSpinBox_valueChanged(self, i):
  561.         self.page_index = i - 1
  562.         self.ExitLabel.setText(self.pages[self.page_index][0])
  563.         self.ExitIcon.setPixmap(self.pages[self.page_index][1])
  564.  
  565.     
  566.     def RefreshTimer_timeout(self):
  567.         self.showExitPage()
  568.  
  569.     
  570.     def associate(self, key = u''):
  571.         beginWaitCursor()
  572.         
  573.         try:
  574.             (alg, mode, secretid) = wifi.getCryptoSuite(self.dev)
  575.         except Error:
  576.             e = None
  577.             self.showIOError(e)
  578.             return None
  579.         else:
  580.             log.debug('Crypto algorithm: %s' % alg)
  581.             log.debug('Crypto mode: %s' % mode)
  582.         finally:
  583.             endWaitCursor()
  584.  
  585.         beginWaitCursor()
  586.         
  587.         try:
  588.             ret = wifi.associate(self.dev, self.network, self.mode, self.security, key)
  589.         except Error:
  590.             e = None
  591.             self.showIOError(e)
  592.             return None
  593.         finally:
  594.             endWaitCursor()
  595.  
  596.  
  597.     
  598.     def NextButton_clicked(self):
  599.         p = self.StackedWidget.currentIndex()
  600.         if p == PAGE_INTRO:
  601.             self.showDevicesPage()
  602.         elif p == PAGE_DEVICES:
  603.             row = self.DevicesTableWidget.currentRow()
  604.             if row != -1:
  605.                 self.device_uri = self.DevicesTableWidget.item(row, 0).device_uri
  606.                 self.mq = device.queryModelByURI(self.device_uri)
  607.                 (back_end, is_hp, bus, model, serial, dev_file, host, zc, port) = device.parseDeviceURI(self.device_uri)
  608.                 self.model = models.normalizeModelName(model).lower()
  609.             
  610.             self.showNetworkPage()
  611.         elif p == PAGE_NETWORK:
  612.             self.security = 'None'
  613.             self.mode = 'Infrastructure'
  614.             self.ss = 0
  615.             row = self.NetworksTableWidget.currentRow()
  616.             if row != -1:
  617.                 i = self.NetworksTableWidget.item(row, 0)
  618.                 if i is not None:
  619.                     self.network = unicode(i.text())
  620.                     log.debug('Selected network SSID: %s' % self.network)
  621.                     (self.n, ok) = i.data(Qt.UserRole).toInt()
  622.                     if ok:
  623.                         self.security = self.networks['encryptiontype-%d' % self.n]
  624.                         log.debug('Security: %s' % self.security)
  625.                         self.mode = self.networks['communicationmode-%d' % self.n]
  626.                         log.debug('Mode: %s' % self.mode)
  627.                         self.ss = self.networks['signalstrength-%d' % self.n]
  628.                         log.debug('Signal strength: %s' % self.ss)
  629.                     
  630.                 
  631.             
  632.             if self.security.lower() != 'none':
  633.                 self.showConfigWifiPage()
  634.             else:
  635.                 self.associate()
  636.                 self.showAssociateProgressDialog()
  637.                 self.showExitPage()
  638.         elif p == PAGE_CONFIGURE_WIFI:
  639.             key = unicode(self.KeyLineEdit.text())
  640.             self.associate(key)
  641.             self.showAssociateProgressDialog()
  642.             self.showExitPage()
  643.         elif p == PAGE_EXIT:
  644.             if self.dev is not None:
  645.                 self.dev.close()
  646.             
  647.             self.close()
  648.         else:
  649.             log.error('Invalid page!')
  650.  
  651.     
  652.     def showAssociateProgressDialog(self):
  653.         AssociateProgressDialog = QProgressDialog(self._WifiSetupDialog__tr('Waiting for printer to connect to the wireless network...'), self._WifiSetupDialog__tr('Cancel'), 0, ASSOCIATE_DELAY, self)
  654.         AssociateProgressDialog.setWindowTitle(self._WifiSetupDialog__tr('HP Device Manager - Please wait...'))
  655.         AssociateProgressDialog.setWindowModality(Qt.WindowModal)
  656.         AssociateProgressDialog.setMinimumDuration(0)
  657.         AssociateProgressDialog.forceShow()
  658.         canceled = False
  659.         for x in range(ASSOCIATE_DELAY):
  660.             AssociateProgressDialog.setValue(x)
  661.             QThread.sleep(1)
  662.             qApp.processEvents()
  663.             if AssociateProgressDialog.wasCanceled():
  664.                 canceled = True
  665.                 break
  666.                 continue
  667.         
  668.         AssociateProgressDialog.setValue(ASSOCIATE_DELAY)
  669.         AssociateProgressDialog.close()
  670.         if canceled:
  671.             if self.dev is not None:
  672.                 self.dev.close()
  673.             
  674.             self.close()
  675.         
  676.  
  677.     
  678.     def BackButton_clicked(self):
  679.         p = self.StackedWidget.currentIndex()
  680.         if p == PAGE_DEVICES:
  681.             self.devices = { }
  682.             self.showIntroPage()
  683.         elif p == PAGE_NETWORK:
  684.             self.showDevicesPage()
  685.         elif p == PAGE_CONFIGURE_WIFI:
  686.             self.showNetworkPage()
  687.         elif p == PAGE_EXIT:
  688.             self.RefreshTimer.stop()
  689.             if self.security.lower() != 'none':
  690.                 self.showConfigWifiPage()
  691.             else:
  692.                 self.showNetworkPage()
  693.         else:
  694.             log.error('Invalid page!')
  695.  
  696.     
  697.     def CancelButton_clicked(self):
  698.         if self.dev is not None:
  699.             self.dev.close()
  700.         
  701.         self.close()
  702.  
  703.     
  704.     def displayPage(self, page):
  705.         self.StackedWidget.setCurrentIndex(page)
  706.         self.updateStepText(page)
  707.  
  708.     
  709.     def setNextButton(self, typ = BUTTON_FINISH):
  710.         if typ == BUTTON_NEXT:
  711.             self.NextButton.setText(self._WifiSetupDialog__tr('Next >'))
  712.         elif typ == BUTTON_FINISH:
  713.             self.NextButton.setText(self._WifiSetupDialog__tr('Finish'))
  714.         elif typ == BUTTON_CONNECT:
  715.             self.NextButton.setText(self._WifiSetupDialog__tr('Connect'))
  716.         
  717.  
  718.     
  719.     def updateStepText(self, p):
  720.         self.StepText.setText(self._WifiSetupDialog__tr('Step %1 of %2').arg(p + 1).arg(self.max_page + 1))
  721.  
  722.     
  723.     def showIOError(self, e):
  724.         FailureUI(self, self._WifiSetupDialog__tr('<b>An I/O error occurred.</b><p>Please check the USB connection to your printer and try again.</p>(%1)').arg(QString(e[0])))
  725.         if self.dev is not None:
  726.             self.dev.close()
  727.         
  728.         self.close()
  729.  
  730.     
  731.     def __tr(self, s, c = None):
  732.         return qApp.translate('WifiSetupDialog', s, c)
  733.  
  734.  
  735.